/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-2-26 下午05:37:23
 *
 * CompanySetupAction.java 
 *
 *******************************************************************/
package com.transer.web.action.passport;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

import com.transer.persistance.bean.User;
import com.transer.persistance.dao.IUserDao;
import com.transer.web.action.TranserActionSupport;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class CompanySetupAction extends TranserActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4288054281285872056L;
	// 日志操作
	private static final Logger logger = Logger.getLogger(LanguageSetupAction.class);
	// 用户操作
	private IUserDao userDao;
	// 用户
	private User dump;
	// 用户备份数据
	private User copy;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		try {
			// 备份用户数据
			copy = (User) BeanUtils.cloneBean(user);
			// 公司名称
			user.setCompanyName(dump.getCompanyName());
			// 公司注册号
			user.setCompanyNumber(dump.getCompanyNumber());
			// 公司联系电话
			user.setContactPhone(dump.getContactPhone());
			// 公司简介
			user.setAboutme(dump.getAboutme().replaceAll("\r\n+", "<br/>"));
			// 保存用户
			userDao.updateUser(user);
		} catch (Exception e) {
			logger.error("保存公司信息设置出错:" + e.getMessage());
			// 保存错误,还愿用户数据
			BeanUtils.copyProperties(user, copy);
			// 保存失败
			return TranserActionSupport.ERROR;
		}

		return TranserActionSupport.SUCCESS;
	}

	/**
	 * @return the userDao
	 */
	public IUserDao getUserDao() {
		return userDao;
	}

	/**
	 * @param userDao
	 *            the userDao to set
	 */
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @return the dump
	 */
	public User getDump() {
		return dump;
	}

	/**
	 * @param dump
	 *            the dump to set
	 */
	public void setDump(User dump) {
		this.dump = dump;
	}
}
